package com.planw.beetl.sql.marker

import com.intellij.codeInsight.daemon.RelatedItemLineMarkerInfo
import com.intellij.lang.java.JavaLanguage
import com.intellij.psi.PsiElement
import com.intellij.psi.search.GlobalSearchScope
import org.jetbrains.kotlin.asJava.finder.JavaElementFinder
import org.jetbrains.kotlin.idea.KotlinLanguage
import org.jetbrains.kotlin.idea.refactoring.memberInfo.qualifiedClassNameForRendering
import org.jetbrains.kotlin.psi.KtClass

class BeetlSqlKotlinLineMarkerProvider : BeetlSqlMapperLineMarkerProvider() {

    override fun collectNavigationMarkers(element: PsiElement, result: MutableCollection<in RelatedItemLineMarkerInfo<*>>) {
        if (element.language == KotlinLanguage.INSTANCE) {
            if (element is KtClass) {
                val finder = JavaElementFinder.getInstance(element.project)
                val psiClass = finder.findClass(element.qualifiedClassNameForRendering(), GlobalSearchScope.allScope(element.project))
                psiClass?.let { super.collectNavigationMarkers(psiClass, result) }
            }
            return
        }
        if(element.language == JavaLanguage.INSTANCE){
            super.collectNavigationMarkers(element, result)
        }
    }
}